package org.eclipse.ea.requisit.manager.services.mapper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class RequirementsAssociations {
	
	private String requirement;
	private Map<String, List<String>> classesMethods;
	private List<String> useCases;
	
	public RequirementsAssociations() {
		this.classesMethods = new HashMap<String, List<String>>();
		this.useCases = new ArrayList<String>();
	}

	public String getRequirement() {
		return requirement;
	}
	
	public List<String> getUseCases() {
		return useCases;
	}

	public Map<String, List<String>> getClassesMethods() {
		return classesMethods;
	}

	public void setClassesMethods(Map<String, List<String>> classesMethods) {
		this.classesMethods = classesMethods;
	}

	public void setUseCases(List<String> useCases) {
		this.useCases = useCases;
	}
	
	public void setRequirement(String requirement) {
		this.requirement = requirement;
	}

	public void addClass(String className) {
		
		if(!classesMethods.containsKey(className)){
			this.classesMethods.put(className, null);
		}
	}
	
	public void addMethod(String className, String methodName) {
		
		List<String> methods = null;
		
		if (classesMethods.containsKey(className)) {
			
			methods = classesMethods.get(className);
			
			if(methods == null) {
				methods = new ArrayList<String>();
			}
			
			methods.add(methodName);
			classesMethods.put(className, methods);

		} else {
			methods = new ArrayList<String>();
			methods.add(methodName);
			classesMethods.put(className, methods);
		}
		
	}
	
	public void addUseCase(String useCaseName) {
		this.useCases.add(useCaseName);
	}
	
	public List<String> getMethods(String className) {
		return classesMethods.get(className);
	}

	public boolean existClass(String className) {
		return classesMethods.containsKey(className);
	}
	
	public int getSizeClasses() {
		return classesMethods.keySet().size();
	}
	
	public int getSizeMethods() {

		Set<String> keys = classesMethods.keySet();
		Iterator<String> it = keys.iterator();
		int size = 0;

		while (it.hasNext()) {

			String key = it.next();

			List<String> methods = classesMethods.get(key);

			if (methods != null) {
				size += methods.size();
			}
		}

		return size;

	}
	
	public int getSizeUseCases() {
		
		return useCases.size();
	}
}
